# Maintainer: leso-kn <info@lesosoftware.com>
pkgname=piper-phonemize
_pkgver=2023.11.14-4
pkgver=${_pkgver/-/.}
pkgrel=5
pkgdesc="C++ library for converting text to phonemes for piper-tts"
url="https://github.com/rhasspy/piper-phonemize"
# x86, riscv64, s390x, loongarch64: not supported by onnxruntime
arch="all !x86 !riscv64 !s390x !loongarch64"
license="MIT AND GPL-3.0-only"
depends_dev="$pkgname-libs"
makedepends="
	cmake
	espeak-ng-dev
	onnxruntime-dev
	py3-gpep517
	py3-pybind11-dev
	py3-setuptools
	py3-wheel
	python3-dev
	samurai
	"
subpackages="
	$pkgname-dev
	py3-$pkgname-pyc
	py3-$pkgname:py3
	$pkgname-libs:_libs
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/rhasspy/piper-phonemize/archive/refs/tags/$_pkgver.tar.gz
	no-rpath.patch
	use-system-espeak-ng.patch
	use-system-onnxruntime.patch
	add-pkgconfig-support.patch
	"
builddir="$srcdir"/piper-phonemize-$_pkgver

case "$CARCH" in
	riscv64) options="!check";;
esac

build() {
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr
	cmake --build build

	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

py3() {
	pkgdesc="Python3 bindings for $pkgname"
	depends="$pkgname=$pkgver-r$pkgrel python3"

	amove usr/lib/python3*
}

_libs() {
	amove usr/lib
}

sha512sums="
0a5e07c98da91fd887a9082d42b7b884277fcb02af3116c71fe0900457528dd432abe2634c837f8fe8b47c718ff9dbc4003ce36d502d6a58c7ecc61fab015776  piper-phonemize-2023.11.14.4.tar.gz
793c4e6b2666bce8840474cc1c927d459ac9e0b8d752777aa4dd17e5b9a6aaa242ef44a9b88d18bc96886f58be4dcb3c8d885dfc26c92d9d0d1fc08626d6da77  no-rpath.patch
7afc438cb3c2af3c1b502a5d9f2360efe26636c8ae346432bc749c20ada3d29e57cafaa92c0779ce3954353f70e9f82bf03e7010019b940f7c17695c5c0e5ed1  use-system-espeak-ng.patch
b7a200fd5cd2a57226e377875a3b0d72d6c99a768c4412efed220629d93abf98c5220721c959986c1e121c29f5ad9c7e9d0e13d3c660128705249e62f4c377c7  use-system-onnxruntime.patch
1cb5e8c0f6bdfc53e6de7422c89b0561586e28fd9c0692d87578e47d1f903b25387c887f23a81621f128a2cd0306a9ef2b5f9cf9d57b25d6a9402ef09e62d5ab  add-pkgconfig-support.patch
"
